﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace STRobot
{
    public partial class SkillAddWnd : Form
    {
        public SkillAddWnd()
        {
            InitializeComponent();
            //单体
            textBox1.Text = Config.Get().useskill.single.key.ToString(); //单体技能key
            textBox7.Text = Config.Get().useskill.single.cd.ToString(); //单体技能cd
            checkBox1.Checked = Config.Get().useskill.single.select;
            //debuff
            textBox11.Text = Config.Get().useskill.debuff.key.ToString(); //单体技能key
            textBox12.Text = Config.Get().useskill.debuff.cd.ToString(); //单体技能cd
            checkBox5.Checked = Config.Get().useskill.debuff.select;
            //AOE
            textBox2.Text = Config.Get().useskill.aoe.key.ToString();
            textBox8.Text = Config.Get().useskill.aoe.cd.ToString();
            checkBox2.Checked = Config.Get().useskill.aoe.select;

            //范围
            textBox5.Text = Config.Get().useskill.aoetrigger.range.ToString();
            textBox6.Text = Config.Get().useskill.aoetrigger.number.ToString();
            textBox13.Text = Config.Get().useskill.aoetrigger.outnumber.ToString();
            checkBox6.Checked = Config.Get().useskill.aoetrigger.outer;
            //回城技能
            textBox3.Text = Config.Get().useskill.home.key.ToString();
            textBox9.Text = Config.Get().useskill.home.cd.ToString();

            //随机技能
            textBox4.Text = Config.Get().useskill.random.key.ToString();
            textBox10.Text = Config.Get().useskill.random.cd.ToString();
        }

        //保存配置
        private void button1_Click(object sender, EventArgs e)
        {
            foreach (var item in this.Controls)
            {
                if (item is TextBox)
                {
                    var t = (TextBox)item;
                    if (t.Text.Length == 0)
                    {
                        MessageBox.Show("所有都为必填项");
                        return;
                    }
                }
                if (item is GroupBox)
                {
                    var t = (GroupBox)item;
                    foreach (var i in t.Controls)
                    {                      
                        if ((i is TextBox) )
                        {
                            var ii = (TextBox)i;
                            if (ii.Text.Length == 0)
                            {
                                MessageBox.Show("所有都为必填项");
                                return;
                            }  
                            
                        }
                    }
                }
            }

            Config.Get().useskill.single.key = textBox1.Text.Length > 0 ?Convert.ToInt32(textBox1.Text) : 0; //单体技能key
            Config.Get().useskill.single.name = "单体";
            Config.Get().useskill.single.cd = textBox7.Text.Length > 0 ? Convert.ToDouble(textBox7.Text) : 1; //单体技能cd
            Config.Get().useskill.single.select = checkBox1.Checked;

            Config.Get().useskill.debuff.key = textBox1.Text.Length > 0 ? Convert.ToInt32(textBox12.Text) : 0; //单体技能key
            Config.Get().useskill.debuff.name = "Debuff";
            Config.Get().useskill.debuff.cd = textBox7.Text.Length > 0 ? Convert.ToDouble(textBox11.Text) : 2; //单体技能cd
            Config.Get().useskill.debuff.select = checkBox5.Checked;

            //AOE
            Config.Get().useskill.aoe.key = textBox2.Text.Length > 0 ? Convert.ToInt32(textBox2.Text) : 0; //
            Config.Get().useskill.aoe.name = "AOE";
            Config.Get().useskill.aoe.cd = textBox8.Text.Length > 0 ? Convert.ToDouble(textBox8.Text) : 1; //
            Config.Get().useskill.aoe.select = checkBox2.Checked;


            //范围
            Config.Get().useskill.aoetrigger.range = textBox5.Text.Length > 0 ? Convert.ToInt32(textBox5.Text) : 4; //
            Config.Get().useskill.aoetrigger.number = textBox6.Text.Length > 0 ? Convert.ToInt32(textBox6.Text) : 4; //
            Config.Get().useskill.aoetrigger.outer = checkBox6.Checked;
            Config.Get().useskill.aoetrigger.outnumber = textBox13.Text.Length > 0 ? Convert.ToInt32(textBox13.Text) : 6; //
            //回城技能
            Config.Get().useskill.home.key = textBox3.Text.Length > 0 ? Convert.ToInt32(textBox3.Text) : 0; //
            Config.Get().useskill.home.name = "回城";
            Config.Get().useskill.home.cd = textBox9.Text.Length > 0 ? Convert.ToDouble(textBox9.Text) : 2; //
            Config.Get().useskill.home.select = checkBox3.Checked;

            //随机技能
            Config.Get().useskill.random.key = textBox4.Text.Length > 0 ? Convert.ToInt32(textBox4.Text) : 0; //
            Config.Get().useskill.random.name = "随机";
            Config.Get().useskill.random.cd = textBox10.Text.Length > 0 ? Convert.ToDouble(textBox10.Text) : 2; //
            Config.Get().useskill.random.select = checkBox4.Checked;
            DialogResult = DialogResult.OK;
        }

    }
}
